module WindSpirit
{
    export class SnsLayer extends WindSpirit.MarskLayer
    {
        public tipLabel: egret.TextField;
        public id = "img2dcode";
        public constructor()
        {
            super();
            var rate = 0.2;
            var codeImg = document.getElementById(this.id);
            if(codeImg)
            {
                codeImg.style.visibility = "visible";
            }
            else
            {
                var gameDiv = document.getElementById("gameDiv");
                codeImg = document.createElement("img");
                codeImg.id = this.id;
                codeImg['src'] = WindSpirit.Config.codeImgUrl;
                var height = parseFloat(gameDiv.style.height);
                var width = height * rate;
                codeImg.style.width = width + "px";
                codeImg.style.height = width + "px";
                codeImg.style.position = "fixed";
                console.log(codeImg.style);
                codeImg.style.zIndex = "9999";
                codeImg.style.marginLeft = -width / 2 + "px";
                codeImg.style.marginTop = height / 2 - width / 2 + "px";
                document.body.insertBefore(codeImg,gameDiv);
            }
            var tipLabel = new egret.TextField;
            tipLabel.size = 45;
            tipLabel.fontFamily = WindSpirit.Const.FONT_FAMILY;
            tipLabel.anchorX = 0.5;
            tipLabel.text = "长按二维码关注我们";
            tipLabel.y = WindSpirit.Util.centerY + rate*WindSpirit.Util.stageH;
            tipLabel.x = WindSpirit.Util.centerX;
            this.addChild(tipLabel);
            this.touchEnabled = true;
            
            this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.touch,this);
        }
        public touch()
        {
            document.getElementById(this.id).style.visibility = "hidden";
            this.parent.removeChild(this);
        }
    }
}